package com.software.controller;


import com.software.dao.InvoiceDAO;
import com.software.entity.Invoice;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/searchInvoiceByName")
public class SearchInvoiceByNumber extends HttpServlet {


    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码的方式
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        //获取输出框中的信息
        String invoiceNumber = request.getParameter("invoiceNumber");


        // 调用DAO层方法获取发票信息列表
        List<Invoice> invoiceList = InvoiceDAO.getInvoicesByNumber(invoiceNumber);

        // 将发票信息列表存储到request属性中
        request.setAttribute("invoiceList", invoiceList);

        // 转发到展示发票信息的JSP页面
        request.getRequestDispatcher("searchInvoice.jsp").forward(request, response);



    }

}
